package com.ruoyi.web.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SuperProduct;
import com.ruoyi.system.service.ISuperProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品Controller
 * 
 * @author xjf
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/product/productinfo")
public class SuperProductController extends BaseController
{
    @Autowired
    private ISuperProductService superProductService;

    /**
     * 查询商品列表
     */
    @PreAuthorize("@ss.hasPermi('product:productinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(SuperProduct superProduct)
    {
//        startPage();
        List<SuperProduct> list = superProductService.selectSuperProductList(superProduct);
        return getDataTable(list);
    }

    /**
     * 导出商品列表
     */
    @PreAuthorize("@ss.hasPermi('product:productinfo:export')")
    @Log(title = "商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SuperProduct superProduct)
    {
        List<SuperProduct> list = superProductService.selectSuperProductList(superProduct);
        ExcelUtil<SuperProduct> util = new ExcelUtil<SuperProduct>(SuperProduct.class);
        util.exportExcel(response, list, "商品数据");
    }

    /**
     * 获取商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:productinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(superProductService.selectSuperProductById(id));
    }

    /**
     * 新增商品
     */
    @PreAuthorize("@ss.hasPermi('product:productinfo:add')")
    @Log(title = "商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SuperProduct superProduct)
    {
        return toAjax(superProductService.insertSuperProduct(superProduct));
    }

    /**
     * 修改商品
     */
    @PreAuthorize("@ss.hasPermi('product:productinfo:edit')")
    @Log(title = "商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SuperProduct superProduct)
    {
        return toAjax(superProductService.updateSuperProduct(superProduct));
    }

    /**
     * 删除商品
     */
    @PreAuthorize("@ss.hasPermi('product:productinfo:remove')")
    @Log(title = "商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(superProductService.deleteSuperProductByIds(ids));
    }

    // 获取根据关键字搜索商品

}
